

package com.hazelcast.internal.nearcache.impl.invalidation;

import com.hazelcast.internal.serialization.impl.SerializationUtil;
import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;

import java.io.IOException;
import java.util.List;

import static java.util.Collections.emptyList;

public class BatchNearCacheInvalidation extends Invalidation {

    private List<Invalidation> invalidations = emptyList();

    public BatchNearCacheInvalidation() {
    }

    public BatchNearCacheInvalidation(String dataStructureName, List<Invalidation> invalidations) {
        super(dataStructureName);
        this.invalidations = invalidations;
    }

    public List<Invalidation> getInvalidations() {
        return invalidations;
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        super.writeData(out);

        SerializationUtil.writeList(invalidations, out);
    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {
        super.readData(in);

        this.invalidations = SerializationUtil.readList(in);
    }

    @Override
    public String toString() {
        return "BatchNearCacheInvalidation{" + "dataStructureName=" + getName() + ", invalidation-count-in-this-batch=" + invalidations.size() + '}';
    }

    @Override
    public int getClassId() {
        return MapDataSerializerHook.NEAR_CACHE_BATCH_INVALIDATION;
    }
}
